home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / leprechn.c < prev    next >
C/C++ Source or Header  |  2000-04-23  |  4KB  |  184 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13. static int x,y,screen_width;
  14. static int last_command;
  15.  
  16. // We reason we need this pending business, is that otherwise, when the guy
  17. // walks on the rainbow, he'd leave a trail behind him
  18. static int pending, pending_x, pending_y, pending_color;
  19.  
  20. WRITE_HANDLER( leprechn_graphics_command_w )
  21. {
  22.     last_command = data;
  23. }
  24.  
  25. WRITE_HANDLER( leprechn_graphics_data_w )
  26. {
  27.     int direction;
  28.  
  29.     if (pending)
  30.     {
  31.         plot_pixel(Machine->scrbitmap, pending_x, pending_y, Machine->pens[pending_color]);
  32.         videoram[pending_y * screen_width + pending_x] = pending_color;
  33.  
  34.         pending = 0;
  35.     }
  36.  
  37.     switch (last_command)
  38.     {
  39.     // Write Command
  40.     case 0x00:
  41.         direction = (data & 0xf0) >> 4;
  42.         switch (direction)
  43.         {
  44.         case 0x00:
  45.         case 0x04:
  46.         case 0x08:
  47.         case 0x0c:
  48.             break;
  49.  
  50.         case 0x01:
  51.         case 0x09:
  52.             x++;
  53.             break;
  54.  
  55.         case 0x02:
  56.         case 0x06:
  57.             y++;
  58.             break;
  59.  
  60.         case 0x03:
  61.             x++;
  62.             y++;
  63.             break;
  64.  
  65.         case 0x05:
  66.         case 0x0d:
  67.             x--;
  68.             break;
  69.  
  70.         case 0x07:
  71.             x--;
  72.             y++;
  73.             break;
  74.  
  75.         case 0x0a:
  76.         case 0x0e:
  77.             y--;
  78.             break;
  79.  
  80.         case 0x0b:
  81.             x++;
  82.             y--;
  83.             break;
  84.  
  85.         case 0x0f:
  86.             x--;
  87.             y--;
  88.             break;
  89.         }
  90.  
  91.         x = x & 0xff;
  92.         y = y & 0xff;
  93.  
  94.         pending = 1;
  95.         pending_x = x;
  96.         pending_y = y;
  97.         pending_color = data & 0x0f;
  98.  
  99.         return;
  100.  
  101.     // X Position Write
  102.     case 0x08:
  103.         x = data;
  104.         return;
  105.  
  106.     // Y Position Write
  107.     case 0x10:
  108.         y = data;
  109.         return;
  110.  
  111.     // Clear Bitmap
  112.     case 0x18:
  113.         fillbitmap(Machine->scrbitmap,Machine->pens[data],0);
  114.         memset(videoram, data, screen_width * Machine->drv->screen_height);
  115.         osd_mark_dirty(0,0,screen_width-1,Machine->drv->screen_height-1,0);
  116.         return;
  117.     }
  118.  
  119.     // Just a precaution. Doesn't seem to happen.
  120.     logerror("Unknown Graphics Command #%2X at %04X\n", last_command, cpu_get_pc());
  121. }
  122.  
  123.  
  124. READ_HANDLER( leprechn_graphics_data_r )
  125. {
  126.     return videoram[y * screen_width + x];
  127. }
  128.  
  129.  
  130. /***************************************************************************
  131.  
  132.   Start the video hardware emulation.
  133.  
  134. ***************************************************************************/
  135. int leprechn_vh_start(void)
  136. {
  137.     screen_width = Machine->drv->screen_width;
  138.  
  139.     if ((videoram = malloc(screen_width*Machine->drv->screen_height)) == 0)
  140.     {
  141.         return 1;
  142.     }
  143.  
  144.     pending = 0;
  145.  
  146.     return 0;
  147. }
  148.  
  149. /***************************************************************************
  150.  
  151.   Stop the video hardware emulation.
  152.  
  153. ***************************************************************************/
  154. void leprechn_vh_stop(void)
  155. {
  156.     free(videoram);
  157. }
  158.  
  159.  
  160. /***************************************************************************
  161.  
  162.   Draw the game screen in the given osd_bitmap.
  163.   Do NOT call osd_update_display() from this function, it will be called by
  164.   the main emulation engine.
  165.  
  166. ***************************************************************************/
  167. void leprechn_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  168. {
  169.     if (full_refresh)
  170.     {
  171.         int sx, sy;
  172.  
  173.         /* redraw bitmap */
  174.  
  175.         for (sx = 0; sx < screen_width; sx++)
  176.         {
  177.             for (sy = 0; sy < Machine->drv->screen_height; sy++)
  178.             {
  179.                 plot_pixel(Machine->scrbitmap, sx, sy, Machine->pens[videoram[sy * screen_width + sx]]);
  180.             }
  181.         }
  182.     }
  183. }
  184.